// 配置路由组件

// import Home from "@/pages/Home";
// import Search from "@/pages/Search";
// import Register from "@/pages/Register";
// import Login from "@/pages/Login";
// import Detail from "@/pages/Detail"
// import AddCartSuccess from "@/pages/AddCartSuccess"
// import ShopCart from "@/pages/ShopCart"
// import Trade from "@/pages/Trade"
// import Pay from "@/pages/Pay"
// import PaySuccess from "@/pages/PaySuccess"
// import Center from '@/pages/Center'
// 二级路由组件
// import myOrder from '@/pages/Center/myOrder'
// import groupOrder from '@/pages/Center/groupOrder';

export default [
  {
    path: "/home",
    component: () => import("@/pages/Home"),
    meta: {
      showFooter: true
    }
  },
  {
    path: "/search/:keyword?",
    component: () => import('@/pages/Search'),
    meta: {
      showFooter: true
    },
    name: "search",
    props: ($route) => ({ keyword: $route.params.keyword, k: $route.query.k })
  },
  {
    path: "/addcartsuccess",
    name: "addcartsuccess",
    component: () => import('@/pages/AddCartSuccess'),
    meta: {
      showFooter: true
    }
  },
  {
    path: "/shopcart",
    component: () => import('@/pages/ShopCart'),
    meta: {
      showFooter: true
    }
  },
  {
    path: "/trade",
    component: () => import('@/pages/Trade'),
    meta: {
      showFooter: true
    },
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // 只有从购物车跳转到交易页面才允许访问
      if (from.path === '/shopcart') {
        next()
      } else {
        next(false) // 如果不是从购物车跳转，阻止访问
      }
    }
  },
  {
    path: "/pay",
    component: () => import('@/pages/Pay'),
    meta: {
      showFooter: true
    },
    beforeEnter: (to, from, next)=>{
      if (from.path === '/trade') {
        next()
      } else {
        next(false);
      }
    }
  },
  {
    path: "/paysuccess",
    component: () => import('@/pages/PaySuccess'),
    meta: {
      showFooter: true
    }
  },
  {
    path: "/center",
    component: () => import('@/pages/Center'),
    meta: {
      showFooter: true
    },
    children: [
      {
        path: "myorder",
        component: () => import('@/pages/Center/myOrder'),
        meta: {
          showFooter: true
        }
      },
      {
        path: "grouporder",
        component: () => import('@/pages/Center/groupOrder'),
        meta: {
          showFooter: true
        }
      },
      {
        path: "/center",
        redirect: "/center/myorder" // 默认重定向到我的订单
      }
    ]
  },
  {
    path: "/detail/:skuId",
    component: () => import('@/pages/Detail'),
    meta: {
      showFooter: true
    }
  },
  {
    path: "/login",
    component: () => import('@/pages/Login'),
    meta: {
      showFooter: false
    }
  },
  {
    path: "/register",
    component: () => import('@/pages/Register'),
    meta: {
      showFooter: false
    }
  },
  // 重定向
  {
    path: "*",
    redirect: "/home"
  }

]